<template>
    <div>
        <NavBar :title="title"></NavBar>
        <van-search v-model="searchval" show-action label="地址" placeholder="请输入搜索关键词" @search="onSearch">
            <template #action>
                <div @click="onClickButton">搜索</div>
            </template>
        </van-search>
        <div v-for="item in searchData">
            <router-link :to="{name:'detail',params:{goods_id:item.goods_id}}">
            <van-card :price="item.goods_price" :title="item.goods_name"
                :thumb="item.goods_small_logo ? item.goods_small_logo : 'https://fastly.jsdelivr.net/npm/@vant/assets/ipad.jpeg'" />
                
       </router-link>    
     </div>
    </div>
</template>

<script setup>
import NavBar from '@/components/NavBar.vue';
const title = '搜索'
import { ref, watch } from 'vue';
const searchval = ref('');
const searchData = ref([])
import { searchApi } from '@/api/api';
import _ from 'lodash'
watch(searchval, (val) => {
    searchApi(val).then(res => {
        console.log(res);
        searchData.value = res.data.message.goods
    })
})
</script>

<style lang="scss" scoped></style>